#include "pch.h"
#include "GraphicsDeviceContext.h"

using namespace Dx;
using namespace Windows::Graphics::Display;

GraphicsDeviceContext::GraphicsDeviceContext()
{
    m_d3dDevice        = d3d::CreateDevice();
    m_d2dFactory       = d2d::CreateFactory(d2d::FactoryType::MultiThreaded);

    m_d2dDevice        = m_d2dFactory.CreateDevice(m_d3dDevice);
    m_d2dDeviceContext = m_d2dDevice.CreateDeviceContext(d2d::DeviceContextOptions::EnableMultiThreadedOptimizations);

    auto displayInfo = DisplayInformation::GetForCurrentView();
 
    float logicalDpi = displayInfo->LogicalDpi;

    m_d2dDeviceContext.SetDpi(logicalDpi, logicalDpi);
    m_d2dDeviceContext.SetUnitMode(d2d::UnitMode::Dips);
}

GraphicsDeviceContext::~GraphicsDeviceContext()
{
}

auto GraphicsDeviceContext::GetD2DDevice()        -> d2d::Device&
{
    return m_d2dDevice;
}

auto GraphicsDeviceContext::GetD3DDevice()        -> d3d::Device&
{
    return m_d3dDevice;
}

auto GraphicsDeviceContext::GetD2DDeviceContext() -> d2d::DeviceContext&
{
    return m_d2dDeviceContext;
}

void GraphicsDeviceContext::SetDPI(float dpiX, float dpiY)
{
    m_d2dDeviceContext.SetDpi(dpiX, dpiY);
}
